package com.cmbchina.designpattern.application.house;

import com.cmbchina.designpattern.application.house.material.Material;
import com.cmbchina.designpattern.application.house.material.Thatch;

/**
 * 茅草房
 */
public class ThatchedHouse {

    /**
     * 需要修建的 地基
     */
    private Material foundation;

    /**
     * 需要修建的 墙
     */
    private Material wall;

    /**
     * 需要修建的 屋顶
     */
    private Material roof;

    /**
     * 需要修建的 窗户
     */
    private Material window;

    /**
     * 修建房屋细节
     */
    public void buildDetail() {
        // 1 第一步，修建地基
        buildFoundation();

        // 2 第二步，修建墙体
        buildWall();

        // 3 第三步，修建窗户
        buildWindow();

        // 4 第四步，修建屋顶
        buildRoof();
    }

    /**
     * 建地基
     */
    private void buildFoundation() {
        this.foundation = new Thatch(100, Material.Unit.KILOGRAM);
    }

    /**
     * 建墙
     */
    private void buildWall() {
        this.wall = new Thatch(50, Material.Unit.KILOGRAM);
    }

    /**
     * 建屋顶
     */
    private void buildRoof() {
        this.roof = new Thatch(30, Material.Unit.KILOGRAM);
    }

    /**
     * 建造窗户
     */
    private void buildWindow() {
        this.window = new Thatch(10, Material.Unit.KILOGRAM);
    }

    /**
     * 计算屋子的抗冲击力，以此判断大灰狼能否摧毁
     *
     * @return 屋子的抗冲击力
     */
    public int breakingStrength() {
        return foundation.overallStrength() + wall.overallStrength() + window.overallStrength() + roof.overallStrength();
    }

    @Override
    public String toString() {
        return this.getClass().getName().split("\\.")[5] + ": Overall Strength-" + breakingStrength();
    }
}
